//
//  CADisplayLink+linkBlock.m
//  NeicunTest
//
//  Created by tanqilong on 16/5/24.
//  Copyright © 2016年 tanqilong. All rights reserved.
//

#import "CADisplayLink+linkBlock.h"
#import <objc/runtime.h>

static const int myBlock = 123;

@implementation CADisplayLink (linkBlock)

+(CADisplayLink *)displayLinkWithblockDo:(void (^)())blockDo {
    CADisplayLink * link = [CADisplayLink displayLinkWithTarget:self selector:@selector(linkDo:)];
    [link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
    objc_setAssociatedObject(link, &myBlock, [blockDo copy], OBJC_ASSOCIATION_COPY_NONATOMIC);
    return link;
}

+(void)linkDo:(CADisplayLink *)displaylink {
    void(^blockDo)() = objc_getAssociatedObject(displaylink, &myBlock);
    blockDo();
}

@end
